package org.jeecg.modules.report.hotel.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.report.hotel.entity.BedReport;
import org.jeecg.modules.report.hotel.entity.HotelRoom;
import org.jeecg.modules.report.hotel.entity.LwgyHotelReport;
import org.jeecg.modules.report.hotel.entity.RoomReport;
import org.jeecg.modules.report.hotel.mapper.HotelReportMapper;
import org.jeecg.modules.report.hotel.service.HotelReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * TODO
 *
 * @author CSD
 * @date 2021-04-08 13:37
 */
@Service
public class HotelReportServiceImpl  extends ServiceImpl<HotelReportMapper, LwgyHotelReport> implements HotelReportService {
    @Autowired
    private HotelReportMapper hotelReportMapper;
    @Override
    public Map<String, Integer> getNoneRoomByCampus(String campus) {
        List<HotelRoom> hotelRooms = hotelReportMapper.getNoneRoomByCampus(campus);
        Map<String,Integer> map = new LinkedHashMap();
        for (HotelRoom hotelRoom : hotelRooms) {
            map.put(hotelRoom.getName(),hotelRoom.getNumber());
        }
        map.put("type",0);//空房间
        return map;
    }

    @Override
    public Map<String, Integer> getUnderRoomByCampus(String campus) {
        List<HotelRoom> hotelRooms = hotelReportMapper.getUnderRoomByCampus(campus);
        Map<String,Integer> map = new LinkedHashMap();
        for (HotelRoom hotelRoom : hotelRooms) {
            map.put(hotelRoom.getName(),hotelRoom.getNumber());
        }
        map.put("type",1);//未满房间
        return map;
    }

    @Override
    public List<HotelRoom> getList(String campus) {
        List<HotelRoom> underRoomList = hotelReportMapper.getUnderRoomByCampus(campus);//未满房间
        List<HotelRoom> noneRoomList = hotelReportMapper.getNoneRoomByCampus(campus);//空房间
        List<HotelRoom>list = new ArrayList<>();
        for (int i = 0; i < underRoomList.size(); i++) {
            HotelRoom noneRoom = noneRoomList.get(i);
            HotelRoom underRoom = underRoomList.get(i);
            noneRoom.setUnderNumber(underRoom.getNumber());
            list.add(noneRoom);
        }
        return list;
    }

    @Override
    public IPage<HotelRoom> queryPageListCustom(Page<HotelRoom> page, String campus) {
        List<HotelRoom> list = getList(campus);
        return page.setRecords(list);
    }

    @Override
    public List<RoomReport> roomUseReport(RoomReport roomReport) {
        String dimension = roomReport.getDimension();
        if(dimension == null){
            roomReport.setDimension("campus_id");
            roomReport.setName("campus_name");
        }else{
            if(dimension.equals("campus_id")){
                roomReport.setName("campus_name");
            }else if(dimension.equals("building_id")){
                roomReport.setName("building_name");
            }
        }
        return hotelReportMapper.roomUseReport(roomReport);
    }

    @Override
    public List<BedReport> bedUseReport(BedReport bedReport) {
        String dimension = bedReport.getDimension();
        if(dimension == null){
            bedReport.setDimension("campus_id");
            bedReport.setName("campus_name");
        }else{
            if(dimension.equals("campus_id")){
                bedReport.setName("campus_name");
            }else if(dimension.equals("building_id")){
                bedReport.setName("building_name");
            }
        }
        return hotelReportMapper.bedUseReport(bedReport);
    }
}
